package ext.csc.component.numbergen.ui;

/*
 * Auther by Christopher
 */
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;

import wt.util.WTException;

import com.ptc.netmarkets.util.misc.NmAction;
import com.ptc.netmarkets.util.misc.NmActionServiceHelper;
import com.ptc.netmarkets.util.misc.NmHTMLActionModel;
import com.ptc.netmarkets.util.table.NmDefaultHTMLTable;

public class NmReportComponent {
	private String[] display;

	private List type;

	private int[] colKey;

	private List content = new ArrayList();

	private List acts = new ArrayList();

	private String name = "";

	// private List display;
	public void setColDisplay(String[] colDis) {
		display = colDis;
	}

	public void setType(List types) {
		type = types;
	}

	public void setCols(int[] cols) {
		colKey = cols;
	}

	public void addContent(String[] cont) {
		content.add(cont);
	}

	public void setContent(List ls) {
		content = ls;
	}

	public void addAction(NmAction act) {
		acts.add(act);
	}

	public void setAction(List actions) {
		acts = actions;
	}

	public void setTableName(String na) {
		name = na;
	}

	public NmDefaultHTMLTable getNmTable() throws WTException {
		NmDefaultHTMLTable table = new NmDefaultHTMLTable();
		table.setRowSelectable(false);
		table.setName(name);
		NmHTMLActionModel actm = new NmHTMLActionModel();
		table.setActionModel(actm);
		if (display != null) {
			if (colKey != null && colKey.length > 0) {
				for (int col = 0; col < colKey.length; col++) {
					table.addColumn(display[col]);
				}
			} else {
				for (int col = 0; col < display.length; col++) {
					table.addColumn(display[col]);
				}
			}
		}
		if (acts != null && acts.size() > 0) {
			for (int i = 0; i < acts.size(); i++) {
				actm.addAction((NmAction) acts.get(i));
			}
		}
		if (content == null || content.size() == 0)
			return table;
		for (int row = 0; row < content.size(); row++) {
			if (colKey != null && colKey.length > 0) {
				for (int col = 0; col < colKey.length; col++) {
					String befor = ((String[]) content.get(row))[colKey[col]];
					if(befor==null){
						befor = "";
					}
					NmTableGUIComponent btnComponent = new NmTableGUIComponent(
							befor);
					table.addCellValue(row, col, btnComponent);
//					System.out.println("add cell   " + befor);
				}
			} else if (colKey == null || colKey.length == 0) {
				String[] aRow = (String[]) content.get(row);
				for (int col = 0; col < aRow.length; col++) {
					String befor = aRow[col];
					if(befor==null){
						befor = "";
					}
					NmTableGUIComponent btnComponent = new NmTableGUIComponent(befor);
					table.addCellValue(row, col, btnComponent);
//					System.out.println("add cell   " + befor);
				}
			}
		}
		
		table.getColumnModel().getColumn(0).setSortable(false);
		return table;
	}
}
